class Solution {
    public int maxProfit(int[] prices, int fee) {
        int[][] f = new int[2][2];
        f[0][0] = 0;
        f[0][1] = -1000000;
        f[1][1] = -1000000;
        f[1][1] = -1000000;
        for (int i = 0; i < prices.length; i++) {
            f[(i+1)&1][1] = Math.max(f[i&1][1], f[i&1][0] - prices[i] - fee);
            f[(i+1)&1][0] = Math.max(f[i&1][0], f[i&1][1] + prices[i]);
        }
        return f[prices.length&1][0];
    }
}
/**
f[i][j] 第i天持有j股的最大利润
i = 1~n
j = 0~1
买入：j == 0: f[i][1] = f[i-1][0] - prices[i] - fee
卖出：j == 1: f[i][j] = f[i-1][1] + prices[i]
观望：f[i][j] = f[i-1][j]
 */
